package com.ruffian.widget.adapter;

import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.PageSliderProvider;

import java.util.List;

/**
 * PageAdapter
 *
 * @author Administrator
 * @date 2021/5/26
 */
public class PageAdapter extends PageSliderProvider {
    private List<Component> list;

    public PageAdapter(List<Component> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return null == list ? 0 : list.size();
    }

    @Override
    public Object createPageInContainer(ComponentContainer componentContainer, int i) {
        componentContainer.addComponent(list.get(i));
        return componentContainer;
    }

    @Override
    public void destroyPageFromContainer(ComponentContainer componentContainer, int i, Object o) {
        componentContainer.removeComponent(list.get(i));
    }

    @Override
    public boolean isPageMatchToObject(Component component, Object o) {
        return component.equals(o);
    }
}
